<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ArticleController;
use App\Http\Controllers\userController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// 主页
Route::get('/', [ArticleController::class, 'articleList'])->name('home');
// 登录|验证
//todo 对密码md5?
Route::get('login', [userController::class,'login'])->name('login');
Route::post('login', [userController::class,'login'])->name('login');
// 登出
Route::get('logout', [userController::class,'logout'])->name('logout');
// 修改密码|验证
Route::get('updatepwd', [userController::class,'updatepwd'])->name('updatepwd');
Route::post('updatepwd/check', [userController::class,'updatepwd'])->name('updatepwdcheck');


// 文章内容页
Route::get('article/{id?}', [ArticleController::class, 'article'])->name('article');
// 管理
Route::get('admin', [UserController::class, 'admin'])->name('admin');
// 文章管理
Route::get('adminArticleList', [ArticleController::class, 'adminArticleList'])->name('adminArticleList');
// 文章Search搜索
Route::get('search', [ArticleController::class, 'search'])->name('search');
// 文章法发布|处理
Route::get('adminInsert', [ArticleController::class, 'insert']);
Route::post('adminInsertCheck', [ArticleController::class, 'insertCheck']);
// 文章删除
Route::get('adminDelete/{id}', [ArticleController::class, 'delete']);
// 文章修改|处理
Route::get('adminUpdate/{id?}', [ArticleController::class, 'update'])->name('update');
Route::post('adminUpdateCheck', [ArticleController::class, 'updateCheck']);
// 删除所有文章
Route::get('adminDeleteAll', [ArticleController::class, 'deleteAll']);


// 调试
Route::get('test', function () {
    return view('test');
});


//api
// 文章Search搜索
Route::get('api/search', [ArticleController::class, 'searchAPI'])->name('searchapi');
// 文章内容页
Route::get('api/article/{id?}', [ArticleController::class, 'articleAPI'])->name('articleapi');


// 404
// 指定异常时的路由
Route::fallback(function () {
    return view('404');
});